<template>
  <div class="container">
    <nav-bar :title="title">
      <span style="color: #333">
        <svg-icon icon-class="share" :width="15" :height="15" />
      </span>
    </nav-bar>

    <Item
      v-for="(item, idx) in purchaseList"
      :key="idx + 10"
      :is-show-step="true"
      :index="item.orderCode?item.orderCode:item.orderId"
      :num="item.goodsCount"
      :max-num="item.goodsCount"
      :min-number="item.goodsCount"
      :thumb="item.payImgUrl"
      :sale-user="item.saleUserName"
      :buy-user="item.buyUserName"
      :title="item.goodsName"
      :price="item.orderPrice | yuan"
      :is-show-checkbox="type==1"
      :time="item.createTime"
      tag-slot="warehouseTagSlot"
      class="warehouse-card"
    >
    </Item>
  </div>
</template>

<script>
import {
  getHistoryRepositoryData
} from '@/api/cart'
import Item from '@/views/warehouse/modules/Item.vue'
import Tabbar from '@/views/warehouse/modules/Tabbar.vue'

export default {
  name: 'WarehouseYes',
  components: {
    Item,
    Tabbar
  },
  data() {
    return {
      purchaseList: [],
      title: ''
    }
  },
  computed: {
  },
  mounted() {
    const type = this.$route.query.type
    const options = {
      1: '今日买单',
      2: '昨日卖单'
    }
    this.title = options[type]
    this.type = type == 2 ? 1:2
    this.getData(this.type)
  },
  methods: {
    getData: async function(type) {
      const res = await getHistoryRepositoryData({ type })
      console.log('仓库订单==', res)
      
      this.purchaseList = res.map.list.map((item) => {
        let date =new Date(item.createTime)
        console.log(date)
        let y = date.getFullYear()
        let M = date.getMonth()>8 ?date.getMonth()+1 : '0'+(date.getMonth()+1)
        let d = date.getDate()>9 ? date.getDate(): '0'+date.getDate()
        let h = date.getHours()>9 ? date.getHours(): '0'+date.getHours()
        let m = date.getMinutes()>9 ? date.getMinutes(): '0'+date.getMinutes()
        let s = date.getSeconds()>9 ? date.getSeconds(): '0'+date.getSeconds()
        item.createTime = `${y}-${M}-${d} ${h}:${m}:${s}`
        return item
      })
      console.log(this.purchaseList)
    },
    
  }
}
</script>

<style scoped lang="scss">
.container{
  // padding-bottom: 120px;
  background-color: #f0f0f0;
  min-height: 100vh;
}
.title-bar {
  width: 100%;
  text-align: center;
  font-size: 28px;
  font-weight: bolder;
  margin: 30px 0;
  overflow: hidden;
}

.warehouse-card {
  width: 100%;
  // background-color: #fff;
  box-sizing: border-box;
  overflow: hidden;

  ::v-deep .van-card__title {
    font-size: 30px;
    font-weight: 600;
  }

  .mt-12 {
    margin-top: 12px;
  }

  ::v-deep .van-tag {
    line-height: 38px;
    font-weight: 600;
  }
}
</style>
